    $(function (){
        //智能推荐加载
        loadRecommend();
        //推荐是否显示
        recommendIsDisplay();
    })

    var cxt = "/knowledge/";

    //推荐是否显示
    function recommendIsDisplay(){
        if(recommendOff==0||recommendOff=="0"){
            $("#recommend").hide();
        }else{
            $("#recommend").show();
        }
    }


    function loadRecommend(){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            url: cxt+"pageview/selectKwDocumentPageviewUserRecords",
            contentType: "application/json;charset=UTF-8",
            success: function(result){
                var str = "";
                var icnos = "<i class=\"fa fa-file-word-o\"></i>";
                var fileSuffixName = "";
                if(result!=null&&result.length>0){
                    for(var i=0;i<result.length;i++){
                        str+="<div class=\"recommend-content-data\">";
                        fileSuffixName = obtainFile(result[i].documentName);  //文件后缀名获取  obtainFile(result[i].documentName)
                        if(fileSuffixName=="doc"||fileSuffixName=="docx"){  //fa fa-file-word-o    --word
                            icnos = "<i class=\"fa fa-file-word-o\"></i>";
                        }
                        if(fileSuffixName=="xls"||fileSuffixName=="xlsx"){  //fa fa-file-excel-o    --excel
                            icnos = "<i class=\"fa fa-file-excel-o\"></i>";
                        }
                        if(fileSuffixName=="ppt"||fileSuffixName=="pptx"){  //fa fa-file-powerpoint-o    --ppt
                            icnos = "<i class=\"fa fa-file-powerpoint-o\"></i>";
                        }
                        if(fileSuffixName=="pdf"){  //fa fa-file-pdf-o    --pdf
                            icnos = "<i class=\"fa fa-file-pdf-o\"></i>";
                        }
                        str+="<div class=\"recommend-content-data-icnos\">"+icnos+"</div>";
                        str+="<div class=\"recommend-content-data-name\" pageviewId=\""+result[i].documentId+"\" inputFile=\""+result[i].documentSaveurl+"\">"+strLengthSub(result[i].documentName,20)+"</div>";
                        str+="<div class=\"recommend-content-data-user black\">"+result[i].pageviewIp+"</div>";
                        str+="<div class=\"recommend-content-data-date black\">"+dateFormat(result[i].pageviewTime)+"</div>";
                        str+="</div>";
                    }
                }else{
                    str+="<div class=\"no-data\">暂无推荐</div>";
                }
                $("#recommend_content").html(str);
            },
            error: function(result){

            }
        })
    }

    //截取字符串长度返回  --str:字符串本体   --leng：截取的字符串长度
    function strLengthSub(str,leng){
        if(str.length>leng){
            str = str.substring(0,leng);
        }else{
            return str;
        }
        str+="...";
        return str;
    }

    //日期格式化
    function dateFormat(time) {
        return time.substring(0,10)
    }


    $.fn.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    };

    //获取文件后缀名
    function obtainFile(fileName){
        var index1=fileName.lastIndexOf(".");
        var index2=fileName.length;
        var suffix=fileName.substring(index1+1,index2);//后缀名
        return suffix;
    }

    //文件推荐点击查看
    $(document).on("click",".recommend-content-data-name",function(e){
        var pageviewId = parseInt($(this).attr("pageviewId"));
        var inputFile = $(this).attr("inputFile");
        inputFile=encodeURI(inputFile)
        var url=cxt+"lookdocument/officeToPdf"
        var data={"inputFile":inputFile,"documentId":pageviewId}
        var newwindow=window.open("about:blank");
        $.post(url,data,function(r){
            debugger;
            console.log(r)
            var url=r.url
            var newUrl = url.replace(/\\/g,"\/");
            var realUrl = baseURL + "localFile"+ newUrl.substr(17)
            newwindow.location.href=realUrl;
            newwindow.focus();
        });
    })

